﻿using System;

namespace Game
{
    public class Player
    {
        public event EventHandler Scored;

        public enum ePlayerType 
        { 
            Mortal, 
            AI 
        }

        private readonly ePlayerType r_PlayerType;
        private string m_Name;
        private int m_Score = 0;
        private readonly AI r_AI;

        public Player(string i_Name, ePlayerType i_PlayerType)
        {
            m_Name = i_Name;
            r_PlayerType = i_PlayerType;
            if (i_PlayerType == ePlayerType.AI)
            {
                r_AI = new AI();
            }
        }

        public AI AI
        {
            get 
            {
                if (r_PlayerType == ePlayerType.AI)
                {
                    return r_AI; 
                }
                else
                {
                    throw new System.Exception("Tried to access AI functionality in a human player");
                }
            }
	    }

        public ePlayerType PlayerType
        {
            get { return r_PlayerType; }
            private set { } 
        }
    
        public int Score
        {
            get { return m_Score; }
            set 
            {
                if (Scored != null)
                { 
                    Scored.Invoke(this, new EventArgs()); 
                }

                m_Score = value; 
            }
        }

        public string Name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }
    }
}
